<div class="container-fluid">
  <div class="row">
    <div class="col-sm-12">
      <div class="panel panel-primary table_border">
        <div class="panel-heading table_new">
          <% if teacher_logged_in? %><h3 class="panel-title">成绩管理: <%= @course.name %></h3>
          <% end %>
          <% if student_logged_in? %><h3 class="panel-title">成绩列表</h3>
          <% end %>
        </div>

        <div class="panel-body" style="min-height: 450px">
          <% if student_logged_in? %>
            <%= link_to "导出", grades_save_url(:format => 'xls'), :class => "btn" %>
          <% end %>
          
          <% if teacher_logged_in? %>
              <div class="row">
                <div class="col-sm-12" style="padding-bottom: 26px">
                  <%= form_tag 'grades/import', method: "post", multipart: true, :class => "form_file" do %>
                      <div class="file_style">
                        <input type="hidden" value="<%= @course.id %>" name="course_id">
                        <%= file_field_tag :excel_file, :class => "fileInput", :size => "28", :onchange => "document.getElementById('textfield').value=this.value" %>
                        <%= submit_tag "上传", :class => "btn" %>
                        <%= link_to "导出", grades_export_url(:course_id => @course.id, :format => 'xls'), :class => "btn" %>
                      </div>
                  <% end %>
                </div>
              </div>
          <% end %>

          <table class="table table-striped table-hover">
            <thead>
            <tr>
              <% if not student_logged_in? %>
                  <th>学号</th>
                  <th>名字</th>
                  <th>专业</th>
                  <th>培养单位</th>
              <% end %>
              <th>课程</th>
              <th>分数</th>
            </tr>
            </thead>
            <tbody>

            <% @grades.each do |grade| %>
                <tr>
                  <% if not student_logged_in? %>
                      <td><%= grade.user.num %></td>
                      <td><%= grade.user.name %></td>
                      <td><%= grade.user.major %></td>
                      <td><%= grade.user.department %></td>
                  <% end %>

                  <td><%= grade.course.name %></td>
                  <td><%= grade.grade %></td>

                  <% if teacher_logged_in? %>
                      <%= form_for grade, url: grade_url(id: grade.id, course_id: grade.course.id), method: :patch do |f| %>
                          <td><%= f.text_field :grade %></td>
                          <td><%= f.submit "提交", class: "btn btn-success btn-xs btn_new" %></td>
                      <% end %>
                  <% end %>

                </tr>
            <% end %>
            </tbody>
          </table>
          <%= will_paginate @grades %>
        </div>
      </div>
    </div>
  </div>
</div>